package com.ruoyi.system.domain;

import com.opencsv.bean.CsvBindByName;

import com.ruoyi.common.utils.DateUtils;
import com.univocity.parsers.annotations.Parsed;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class CSVCatalystsQualityEntry {

    @Parsed(field = "batchNo")
    private String batchNo;
    @Parsed(field = "width")
    private String width;
    @Parsed(field = "height")
    private String height;
    @Parsed(field = "floor")
    private String floor;
    @Parsed(field = "area")
    private String area;
    @Parsed(field = "thirdBatch")
    private String thirdBatch;
    @Parsed(field = "thirdNo")
    private String thirdNo;
    @Parsed(field = "createTime")
    private String  createTime;
    @Parsed(field = "weight")
    private String weight;

    public SysCatalystsQuality toCatalystsQuality(){
        SysCatalystsQuality catalystsQuality = new SysCatalystsQuality();
        if (this.batchNo != null){
            //this.batchNo  拆分为batchId和batchNo，前6位为batchId 后三位为batchNo
            catalystsQuality.setBatchId(this.batchNo.substring(0,6));
            catalystsQuality.setBatchNo(this.batchNo.substring(6));
        }
        catalystsQuality.setWidth(new BigDecimal(this.width));
        catalystsQuality.setHeight(new BigDecimal(this.height));
        catalystsQuality.setFloor(Integer.parseInt(this.floor));
        catalystsQuality.setArea(new BigDecimal(this.area));
        catalystsQuality.setThirdBatchId(this.thirdBatch);
        catalystsQuality.setThirdBatchNo(this.thirdNo);
        catalystsQuality.setWeight(new BigDecimal(this.weight));
        catalystsQuality.setUploadTime(new Date());
        //this.createTime 转换为date
        Date createTime = DateUtils.parseDate(this.createTime);
        catalystsQuality.setCreateTime(createTime);
        return catalystsQuality;
    }

}
